跳转至

DRL:面向模式图扩展的事务安全企业级 NL2SQL 确定性关系中间件层

文章背景与核心概要

在企业级 OLTP(联机事务处理)目录中部署自然语言接口(NL2SQL)时,系统往往会在规模扩大时失效。随着模式图(schema-graphs)的不断扩展,语义解析器会由于输入规模超出稳定的大语言模型(LLM)注意力预算而崩溃。本文引入了 DRL(Deterministic Relational Middleware Layer,确定性关系中间件层),这是一种安全的架构管道,介于前端与 SQL 后端之间。DRL 利用动态上下文修剪、关系 AST 类型化以及事务安全验证(如 EXPLAIN 门控和 NULL 防护),来限制上下文窗口并标记操作性静默散度(\(\text{SD}_{op}\))。

该研究在 PostgreSQL 和 MySQL 上进行了评估,为企业级数据库系统工程作出了重要贡献,将 NL2SQL 从单纯的排行榜竞赛重新定义为一个可靠的、感知执行计划的准入与验证挑战。


📌 Summary

Deploying natural-language interfaces (NL2SQL) for enterprise OLTP catalogs often fails at scale. As schema-graphs expand, semantic parsers collapse because input sizes inflate beyond stable Large Language Model (LLM) attention budgets.

This paper introduces DRL (Deterministic Relational Middleware Layer), a safe architectural pipeline that sits between front-ends and SQL backends. DRL utilizes dynamic context pruning, relational AST typing, and transactional safeguard verification (such as EXPLAIN gating and NULL guards) to bound context windows and flag operational silent divergence (\(\text{SD}_{op}\)).

Evaluated across PostgreSQL and MySQL, the research offers significant contributions to enterprise database systems engineering, redefining NL2SQL from a leaderboard exercise into a reliable, plan-aware admission and verification challenge.


🛠️ Key Contributions & Architecture

  1. OLTP Schema-Graph Scaling Model: A formalized approach to analyzing how enterprise database schemas grow and impact parser performance.
  2. Workload Verification Suite: A 1,000-pair benchmark suite designed for testing transactional safety and query execution accuracy.
  3. Baselines (B0–B3): Systematic baseline progression from naive catalog prompting to schema-linked hints and dynamic routing.
  4. Enterprise NL2SQL Failure Taxonomy: A structured classification of where and why natural-language-to-SQL conversions fail in production settings.
  1. OLTP 模式图扩展模型: 一种形式化方法,用于分析企业数据库模式如何增长并影响解析器性能。
  2. 工作负载验证套件: 一个包含 1,000 对数据的基准测试套件,旨在测试事务安全性和查询执行准确性。
  3. 基线(B0–B3): 从朴素的目录提示词到模式链接提示词以及动态路由的系统化基线演进。
  4. 企业级 NL2SQL 失败分类学: 对生产环境中自然语言转 SQL 转换失败的位置和原因进行的结构化分类。

📊 Performance & Evaluation Highlights

  • Context Reduction:
  • Schema-linked hints (B1) achieve a 76% context reduction over naive full-catalog prompting (B0).
  • DRL's dynamic router (B2) achieves a 92% context reduction with a pruning \(p95\) of 0.58 ms and a middleware overhead \(p95\) of 4.6 ms.
  • Execution Match Accuracy: Under a corrected evaluation harness, GPT-4o, Claude Sonnet 4.5, and Gemini 2.5 Flash achieved execution match scores of 52.9%, 52.8%, and 52.1% respectively.
  • Error Analysis:
  • \(\text{SD}_{op}\) successfully flags 89–100% of false-positive EXPLAIN-passing queries.
  • GPT-4o failures are primarily dominated by semantic and filter errors (254 out of 471), whereas column hallucination plays a minor role (47 out of 471).
  • The Benchmark Defect Insight: A single regular-expression defect in an evaluation post-processor silently suppressed accuracy and manufactured a false 4–10% cross-vendor performance gap. Once corrected, the gap vanished—highlighting that evaluation benchmark code demands the exact same rigor and scrutiny as the models being tested.
  • 上下文缩减:
  • 相比朴素的全目录提示词(B0),模式链接提示词(B1)实现了 76% 的上下文缩减
  • DRL 的动态路由器(B2)实现了 92% 的上下文缩减,其修剪延迟 \(p95\)0.58 毫秒,中间件开销延迟 \(p95\)4.6 毫秒
  • 执行匹配准确率: 在修正后的评估框架下,GPT-4oClaude Sonnet 4.5Gemini 2.5 Flash 的执行匹配得分分别为 52.9%52.8%52.1%
  • 错误分析:
  • \(\text{SD}_{op}\) 成功标记了 89–100% 的假阳性 EXPLAIN 通过查询。
  • GPT-4o 的失败主要由语义和过滤错误主导(471个中占 254 个),而列幻觉的影响较小(471个中占 47 个)。
  • 基准测试缺陷洞察: 评估后处理程序中的一个正则表达式缺陷默默地压低了准确率,并制造了 4–10% 的虚假跨厂商性能差距。一旦纠正,该差距便消失了——这凸显了评估基准测试代码需要与被测试模型保持完全相同的严谨性和审查力度。